package net.wesley.android.city;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import android.os.Handler;
import android.os.Message;

import net.wesley.android.City;
import net.yebaihe.sdk.HttpConnection;

public class WuLuMuQi extends City {

	private Handler request1handler=new Handler(){
		public void handleMessage(Message message){
			switch (message.what){
			case HttpConnection.DID_ERROR://DID ERROR
				callback.onComplete(-1, "");
				break;
			case HttpConnection.DID_SUCCEED://DID SUCC
				String body=(String)message.obj;
				int index=body.indexOf("最后处理时间</td>");
				if (index>0){
					String str=body.substring(index+11).split("返回查询系统")[0];
					String[] rows=str.split("<tr");
					String retvalue="";
					for (int i=1;i<rows.length-1;i++){
						String[] cols=rows[i].split("<td");
						String[] values=cols[3].split("</")[0].split(">");
						String shijian="";
						if (values.length>1){
							shijian=values[1].trim();
						}
						if (shijian.equals("")) shijian="未提供时间";
						String didian="未提供地点";
						String code="未提供编码";
						retvalue+=String.format("shijian:%s\ndidian:%s\ncode:%s\n\n",shijian,didian,code);
 					}
					callback.onComplete(rows.length-2, retvalue);
				}
				else{
					callback.onComplete(-10001, "");
				}
				break;
			}
		}
	};

	public void requestParamsFinish(String[] values) {
		try {
			new HttpConnection(ctx,request1handler,"GBK").post("http://www.wlmqwb.com/question/car/search.asp", 
					String.format("stu_go=%s&B1=%%C8%%B7%%C8%%CF%%B2%%E9%%D1%%AF",
							URLEncoder.encode(chepai,"GBK")));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

	@Override
	public boolean match(String chepai) {
		return chepai.startsWith("新A");
	}

	@Override
	public String[] paramDesc() {
		return null;
	}

}
